# Maintainer: Jan Alexander Steffens (heftig) <heftig@archlinux.org>

pkgname=libphonenumber
pkgver=8.13.4
pkgrel=2
epoch=1
pkgdesc="Google's common library for parsing, formatting, and validating international phone numbers"
url="https://github.com/googlei18n/libphonenumber"
arch=(x86_64)
license=(Apache)
depends=(icu protobuf abseil-cpp)
makedepends=(cmake gtest git jre-openjdk-headless)
_commit=a27ae9774997a940cbe737a0575c1b870482c473  # tags/v8.13.4^0
source=("git+$url#commit=$_commit")
sha256sums=('SKIP')

pkgver() {
  cd $pkgname
  git describe --tags | sed 's/^libphonenumber-\|^v//;s/[^-]*-g/r&/;s/-/+/g'
}

prepare() {
  cd $pkgname
  sed -e 's|CMAKE_CXX_STANDARD 11|CMAKE_CXX_STANDARD 17|' -i tools/cpp/CMakeLists.txt # Fix build with abseil-cpp 2023
}

build() {
  local cmake_options=(
    -DCMAKE_INSTALL_PREFIX=/usr
    -DCMAKE_BUILD_TYPE=None
    -DCMAKE_CXX_STANDARD=17
    -DUSE_BOOST=OFF
    -DUSE_STDMUTEX=ON
  )

  cmake -S $pkgname/cpp -B build "${cmake_options[@]}"
  cmake --build build
}

check() {
  cmake --build build --target tests
}

package() {
  depends+=(libicu{uc,i18n}.so libprotobuf.so)
  provides+=(libgeocoding.so libphonenumber.so)

  DESTDIR="$pkgdir" cmake --install build
}

# vim:set sw=2 sts=-1 et:
